<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .container {
        display: flex;
      }
      .box {
        width: 50rem;
        height: 26.667rem;
      }
      .box1 {
        background-color: pink;
      }
      .box2 {
        background-color: deeppink;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box box1"></div>
      <div class="box box2"></div>
    </div>
    <script>
      /*
        问题：100px转多少rem？ 设计稿iPhone6/7/8 375px

          1 rem = 3.75px
          x rem = 100px
              x = 26.667rem

              x = 设计稿大小 / 3.75
      */
      const docEl = document.documentElement;
      // 设置 1rem = 屏幕宽度 / 100
      function setRemUnit() {
        const rem = docEl.clientWidth / 100;
        docEl.style.fontSize = rem + "px";
      }
      setRemUnit();
      // 当浏览器大小调整或后退时，重新更新字体大小
      window.addEventListener("resize", setRemUnit);
    </script>
  </body>
</html>
